/*
 * Copyright (C) 2007-2012 by XDEV Software, All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 3.0 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
package xdev.db.sql;


import net.jadoth.sqlengine.internal.SqlAggregateAVG;
import net.jadoth.sqlengine.internal.SqlAggregateCOUNT;
import net.jadoth.sqlengine.internal.SqlAggregateMAX;
import net.jadoth.sqlengine.internal.SqlAggregateMin;
import net.jadoth.sqlengine.internal.SqlAggregateSUM;
import net.jadoth.sqlengine.internal.SqlFunctionABS;
import net.jadoth.sqlengine.internal.SqlFunctionCOALESCE;
import net.jadoth.sqlengine.internal.SqlFunctionMOD;
import net.jadoth.sqlengine.internal.SqlFunctionROW_NUMBER;
import net.jadoth.sqlengine.internal.SqlFunctionSUBSTRING;
import net.jadoth.sqlengine.internal.SqlxFunctionCONCAT;
import net.jadoth.sqlengine.internal.SqlxFunctionROUND;
import net.jadoth.sqlengine.internal.SqlxFunctionTO_CHAR;
import net.jadoth.sqlengine.internal.SqlxFunctionTO_NUMBER;


public final class Functions
{
	private Functions()
	{
	}
	

	public static Expression AVG(Object value)
	{
		return new Expression(new SqlAggregateAVG(SqlObject.expose(value)));
	}
	

	public static Expression COUNT()
	{
		return new Expression(new SqlAggregateCOUNT());
	}
	

	public static Expression COUNT(Object value)
	{
		return new Expression(new SqlAggregateCOUNT(SqlObject.expose(value)));
	}
	

	public static Expression MAX(Object value)
	{
		return new Expression(new SqlAggregateMAX(SqlObject.expose(value)));
	}
	

	public static Expression MIN(Object value)
	{
		return new Expression(new SqlAggregateMin(SqlObject.expose(value)));
	}
	

	public static Expression SUM(Object value)
	{
		return new Expression(new SqlAggregateSUM(SqlObject.expose(value)));
	}
	

	public static Expression ABS(Object value)
	{
		return new Expression(new SqlFunctionABS(SqlObject.expose(value)));
	}
	

	public static Expression COALESCE(Object... values)
	{
		return new Expression(new SqlFunctionCOALESCE(SqlObject.expose(values)));
	}
	

	public static Expression MOD(Object dividend, Object divisor)
	{
		return new Expression(new SqlFunctionMOD(SqlObject.expose(dividend),SqlObject
				.expose(divisor)));
	}
	

	public static Expression ROW_NUMBER()
	{
		return new Expression(new SqlFunctionROW_NUMBER());
	}
	

	public static Expression SUBSTRING(Object string, int start)
	{
		return new Expression(new SqlFunctionSUBSTRING(SqlObject.expose(string),start));
	}
	

	public static Expression SUBSTRING(Object string, int start, int length)
	{
		return new Expression(new SqlFunctionSUBSTRING(SqlObject.expose(string),start,length));
	}
	

	public static Expression CONCAT(Object left, Object right)
	{
		return new Expression(
				new SqlxFunctionCONCAT(SqlObject.expose(left),SqlObject.expose(right)));
	}
	

	public static Expression ROUND(Object value, int decimals)
	{
		return new Expression(new SqlxFunctionROUND(SqlObject.expose(value),decimals));
	}
	

	public static Expression TO_CHAR(Object expression, Object format)
	{
		return new Expression(new SqlxFunctionTO_CHAR(SqlObject.expose(expression),SqlObject
				.expose(format)));
	}
	

	public static Expression TO_NUMBER(Object expresion)
	{
		return new Expression(new SqlxFunctionTO_NUMBER(SqlObject.expose(expresion)));
	}
}
